﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PureMVC.Interfaces;
using PureMVC.Patterns;

namespace Spring.PureMVC.DynamicContext.Test.Mediators
{
    public class FormMediator : Mediator
    {
        public FormMediator(string name) : base(name) { }

        public override IEnumerable<string> ListNotificationInterests
        {
            get { return new[] { "showForm", "closeForm", "showInteger" }; }
        }

        public override void HandleNotification(INotification notification)
        {
            var form = (Form)ViewComponent;
            switch (notification.Name)
            {
                case "showForm":
                    Application.Run(form);
                    break;
                case "closeForm":
                    form.Close();
                    break;
                case "showInteger":
                    {
                        var integer = Facade.RetrieveProxy("integerProxy").Data.ToString();
                        var g = (Graphics)notification.Body;
                        g.Clear(form.BackColor);
                        g.DrawString(integer, form.Font, Brushes.Red,
                                                         new Point(form.Width / 2,10));
                        break;
                    }
            }
        }

        public void OnPaint(object sender, PaintEventArgs e)
        {
            SendNotification("showInteger", e.Graphics);
        }
    }
}
